package com.twu.biblioteca;

/**
 * Created with IntelliJ IDEA.
 * User: aulme
 * Date: 05/07/2013
 * Time: 14:39
 * To change this template use File | Settings | File Templates.
 */
public class User {
    private final String libraryNumber;
    private final int passwordHash;
    private final String name;
    private final String email;
    private final String phoneNumber;

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public String getEmail() {
        return email;
    }
    public String getName() {
        return name;
    }

    public String getLibraryNumber() {
        return libraryNumber;
    }

    public boolean isPasswordCorrect(String password) {
        return this.passwordHash == password.hashCode();
    }

    public User(String libraryNumber, int passwordHash, String name, String email, String phoneNumber) {
        this.name = name;
        this.email = email;
        this.phoneNumber = phoneNumber;
        if(!isLibraryNumberCorrectlyFormatted(libraryNumber)) {
            throw new IllegalArgumentException("Library number is not of the correct format");
        }

        this.libraryNumber = libraryNumber;
        this.passwordHash = passwordHash;
    }

    private boolean isLibraryNumberCorrectlyFormatted(String libraryNumber) {
        String pattern = "\\d{3}-\\d{4}";
        return libraryNumber.matches(pattern);
    }
}
